<?php
	$admin_info 		= new Zendvn_System_Info();
	$admin_info 		= $admin_info->getMemberInfo();
	//----------------------- INPUT ELEMENTS -------------------//
	$name 				= $this->formText ( 'name', $this->Item['name'], array ('class' => 'txtmedium') ) . '<div class="view_error" id="view_name"></div>';
	$ngaybatdau			= $this->formText ( 'ngaybatdau', $this->Item['ngaybatdau'], array ( 'class' => 'txtmedium hasDatePicker', 'title' => 'ngày / tháng / năm' ) ) . '<div class="view_error" id="view_ngaybatdau"></div>';
	$ngayketthuc		= $this->formText ( 'ngayketthuc', $this->Item['ngayketthuc'], array ( 'class' => 'txtmedium hasDatePicker', 'title' => 'ngày / tháng / năm' ) ) . '<div class="view_error" id="view_ngayketthuc"></div>';
	$dukien_sotienthuchien 	= $this->formText ( 'dukien_sotienthuchien', $this->Item['dukien_sotienthuchien'], array ('class' => 'txtshort auto_numberic') );
	$dukien_sotiendatduoc 	= $this->formText ( 'dukien_sotiendatduoc', $this->Item['dukien_sotiendatduoc'], array ('class' => 'txtshort auto_numberic') );
	$dukien_soluongkhachhang= $this->formText ( 'dukien_soluongkhachhang', $this->Item['dukien_soluongkhachhang'], array ('class' => 'txtshort auto_numberic') );
	$tylehoanthanhcongviec	= $this->formText ( 'tylehoanthanhcongviec', $this->Item['tylehoanthanhcongviec'], array ('class' => 'txtshort auto_numberic', 'maxlength' => 3) );
	
	$option 			= array('Không','Có');
	if(isset($this->Item['status'])){
		$trangthai 		= $this->Item['status'];
	}else{
		$trangthai 		= 1;
	}
	$status 			= $this->formRadio('status',$trangthai,null,$option, ' ');
	if(isset($this->Item['order'])){
		$order 			= $this->Item['order'];
	}else{
		$order 			= 255;
	}
	$order 				= $this->formText ('order', $order, array ('class' => 'txtshort' ) );
	$content 			= $this->cmsEditor('content',htmlspecialchars_decode($this->Item['content']),array('toolbar'=>'MyToolbar', 'language'=>'vi', 'skin' => 'v2'), 'auto', 200, true, 500, false);

	$title 				= $this->formText ( 'title', $this->Item['title'], array ('class' => 'txtlong') );
	$noidungemail		= $this->cmsEditor('noidungemail',htmlspecialchars_decode($this->Item['noidungemail']),array('toolbar'=>'MyToolbar', 'language'=>'vi', 'skin' => 'v2'), 'auto', 200, true, 500, false);
	$file				= '<img src="" id="image_file" style="width:0;height:0;">';
	$file	 			= $this->cmsUserFiles('file', $this->Item['file'], 'Chọn File', 'file', $options = array('class' => 'txtfile') ) . $file;
	
	$optionTrangthai	= array('0' => 'Sắp triển khai', '1' => 'Đang triển khai', '2' => 'Đã kết thúc', '3' => 'Tạm dừng', '4' => 'Đã hủy');
	$trangthai			= $this->formSelect ( 'trangthai', $this->Item['trangthai'], array('style' => 'min-width:256px;'), $optionTrangthai);
	
	unset($this->Category[0]);
	$id_cat = $this->Item['id_cat'];
	if(!is_array($this->Item['id_cat'])){
		$id_cat = explode(',', $this->Item['id_cat']);
	}
	$category			= $this->formMultiCheckbox( 'id_cat', $id_cat, array(), $this->Category, ' ');
?>
<div class="left_content">
	<?php echo $this->render($this->arrParam['controller'] . '/toolbar/left.php');?>
</div>

<div class="right_content">
	<div class="appContent">
		<form action="" method="post" name="appForm">
			<?php echo $this->render($this->arrParam['controller'] . '/toolbar/index.php');?>
			<?php
				//-------------------- SESSAGES ERROR ------------------
				if(count($this->messageError)>0){
					foreach ($this->messageError AS $key => $val){
						echo '<div class="listError" data="'.$key.'" rel="' . $val . '"></div>';
					}
					echo '<div class="thongbaoError goc5">Có lỗi trong quá trình xử lý.</div>';
				} 
			?>
			<div id="tabs">
				<ul>
					<li><a href="#tabs-1">Thông tin chung</a></li>
					<li><a href="#tabs-2">Danh sách khách hàng</a></li>
					<li><a href="#tabs-3">Nội dung email</a></li>
				</ul>
				<div id="tabs-1">
					<div class="tblForm">
						<div class="tbl_content">
							<table class="tbl">
								<tr>
									<td class="label">Tên chiến dịch <span class="red">*</span></td>
									<td><?php echo $name;?></td>
									
									<td class="label">Dự kiến số tiền thực hiện</td>
									<td><?php echo $dukien_sotienthuchien;?> <span class="note">(VNĐ)</span></td>
								</tr>
								<tr>
									<td class="label">Ngày bắt đầu</td>
									<td><?php echo $ngaybatdau;?></td>
									
									<td class="label">Dự kiến số tiền đạt được</td>
									<td><?php echo $dukien_sotiendatduoc;?> <span class="note">(VNĐ)</span></td>
								</tr>
								<tr>
									<td class="label">Ngày kết thúc</td>
									<td><?php echo $ngayketthuc;?></td>
									
									<td class="label">Dự kiến số lượng KH</td>
									<td><?php echo $dukien_soluongkhachhang;?></td>
								</tr>
								<tr>
									<td class="label">Trạng thái</td>
									<td><?php echo $trangthai;?></td>
									
									<td class="label">Tỷ lệ hoàn thành công việc</td>
									<td><?php echo $tylehoanthanhcongviec;?> <span class="note">(%)</span></td>
								</tr>
								<tr>
									<td class="label">Nhân viên thực hiện</td>
									<td>
										<div class="divChonUser divChonUserLong" id="divChonUser">
											<?php
											if(!empty($this->Item['id_user'])){
												$id_user = $this->Item['id_user'];
												if(!is_array($this->Item['id_user'])){
													$id_user = explode(',', $this->Item['id_user']);
												}
												foreach ($id_user AS $key => $val){
													$name_alias = $this->Users[$val]['name'];
													if($this->Users[$val]['alias'] != ''){
														$name_alias = $this->Users[$val]['name'] . ' (' . $this->Users[$val]['alias'] . ')';
													}
													echo '<span class="item goc3" id="'.$this->Users[$val]['id'].'" title="'.$this->Users[$val]['chucvu_name'].' - '.$this->Users[$val]['phongban_name'].'">'.$name_alias.'<a href="javascript:void(0)" class="delete" title="Xóa" onclick="xoaMotUser('.$this->Users[$val]['id'].', \'divChonUser\')"></a></span>';
													echo '<input id="'.$this->Users[$val]['id'].'" type="hidden" name="id_user[]" value="'.$this->Users[$val]['id'].'">';
												}
											} 
											?>
										</div>
										<a onclick="showListUser('divChonUser', 'id_user')" href="javascript:void(0)" class="showListUser" id="showListUser">Show</a>
										<a onclick="xoaTrangDiv('divChonUser')" href="javascript:void(0)" class="deleteListUser">Delete</a>
									</td>
									
									<td class="label">Loại chiến dịch</td>
									<td>
										<div style="width: 200px;"><?php echo $category;?></div>
									</td>
								</tr>
								
								<tr>
									<td class="label">Thứ tự</td>
									<td><?php echo $order;?></td>
								</tr>
								<tr>
									<td class="label">Hiển thị</td>
									<td><?php echo $status;?></td>
								</tr>
								<tr>
									<td class="label">Nội dung</td>
									<td colspan="3"><?php echo $content;?></td>
								</tr>
							</table>
						</div>
					</div>
				</div>
				<div id="tabs-2">
					<div class="tblForm">
						<div class="tbl_content">
							<?php
								$optionsKhoahoc = $this->Khoahoc;
								unset($optionsKhoahoc[0]);
								$id_khtn 		= '';
								$id_khktd 		= '';
								$id_khoahoc_clb = '';
								$id_khoahoc 	= '';
								if(!empty($this->Item['filter'])){
									$filter = unserialize($this->Item['filter']);
									$id_khtn 		= $filter['id_khtn'];
									$id_khktd 		= $filter['id_khktd'];
									$id_khoahoc_cbl = $filter['id_khoahoc_clb'];
									$id_khoahoc_cbl = $filter['id_khoahoc_clb'];
									$id_khoahoc 	= $filter['id_khoahoc'];
								}
								$filterKhoahocAll = $this->formCheckbox('id_khoahoc_all', $this->Item['id_khoahoc_all'], array(), array('-1' => 'Chọn tất cả'));
								$filterKhoahoc = $this->formMultiCheckbox('id_khoahoc', $id_khoahoc, array(), $optionsKhoahoc, ' ');
							?>
							<fieldset class="adminField">
								<legend>Bộ lọc</legend>
								<table class="tblFilter">
									<tr>
										<td class="item" id="filerKhoahoc">
											<div class="noidung">
												<label for="id_khoahoc_all"><input type="checkbox" value="0" id="id_khoahoc_all" name="id_khoahoc_all" <?php if(isset($this->Item['id_khoahoc_all'])) echo 'checked="checked"';?>>Chọn tất cả</label>
												<label for="id_khtn"><input type="checkbox" value="1" id="id_khtn" name="id_khtn" <?php if(isset($id_khtn)) echo 'checked="checked"';?>>Khách hàng tiềm năng</label>
												<label for="id_khktd"><input type="checkbox" value="1" id="id_khktd" name="id_khktd" <?php if(isset($id_khktd)) echo 'checked="checked"';?>>Khách hàng không theo dõi</label>
												<label for="id_khoahoc_clb"><input type="checkbox" value="1" id="id_khoahoc_clb" name="id_khoahoc_clb" <?php if(isset($id_khoahoc_cbl)) echo 'checked="checked"';?>>Khách hàng từ CLB</label>
												<?php echo $filterKhoahoc;?>
											</div>
										</td>
									</tr>
								</table>
								<script type="text/javascript">
									$('#id_khoahoc_all').click(function(){
										if($(this).is(':checked')){
											$('input[type=checkbox]', '#filerKhoahoc').prop('checked', true);
										}else{
											$('input[type=checkbox]', '#filerKhoahoc').prop('checked', false);
										}
									});
									
									$('input[type=checkbox]', '#filerKhoahoc').click(function(){
										if($(this).is(':checked')){
											kiemtraCheck('#filerKhoahoc');
										}else{
											unKiemtraCheck('#filerKhoahoc');
										}
									});
									function kiemtraCheck(idAll){
										var number = 0;
										var numberItem = $(idAll + ' input[type=checkbox]').size();
										$(idAll + ' input[type=checkbox]').each(function(index){
											if(index > 0){
												if($(this).is(':checked')){
													number++;
												}
											}
										});
										if(number == (numberItem - 1)){
											$(idAll + ' input[type=checkbox]:first').prop('checked', true);
										}
									}
									function unKiemtraCheck(idAll){
										$(idAll + ' input[type=checkbox]:first').prop('checked', false);
									}

									function loadKhachhang(){
										var itemCheck = 0;
										$('.tblFilter input[type=checkbox]').each(function(index){
											if($(this).is(':checked')){
												itemCheck++;
											}
										});
										if(itemCheck > 0){
											$('body').append('<div class="loading_page"></div>');
											var id_khtn 		= '';
											var id_khktd 		= '';
											var id_khoahoc_clb 	= '';
											var id_khoahoc 		= '';
											var arrCid			= '';
											var arrKhachhang	= '';
											var id				= '';
											var strLink			= '';
											<?php
											if(!empty($this->arrParam['id'])) { 
											?>
											id					= '/id/' + <?php echo $this->arrParam['id'];?>;
											<?php
											} 
											?>
											if($('#id_khtn').is(':checked')){
												id_khtn = '/id_khtn/' + $('#id_khtn').attr('value');
											}
											if($('#id_khktd').is(':checked')){
												id_khktd = '/id_khktd/' + $('#id_khktd').attr('value');
											}
											if($('#id_khoahoc_clb').is(':checked')){
												id_khoahoc_clb = '/id_khoahoc_clb/' + $('#id_khoahoc_clb').attr('value');
											}
											var i_kh = 0;
											$('#filerKhoahoc input[type=checkbox]').each(function(index){
												if(index > 1){
													if($(this).is(':checked')){
														i_kh++;
														if(i_kh == 1){
															id_khoahoc += $(this).attr('value');
														}else{
															id_khoahoc += ',' + $(this).attr('value');
														}
													}
												}
											});
											if(id_khoahoc != ''){
												id_khoahoc = '/id_khoahoc/' + id_khoahoc;
											}
											strLink = id_khoahoc_clb + id_khoahoc + id + id_khtn + id_khktd;
											arrCid = <?php echo json_encode($this->Item['cid']);?>;
											arrKhachhang = <?php echo json_encode($this->Khachhang);?>;
											var url = '<?php echo $this->baseUrl('default/ajax/ajax-khachhang');?>' + strLink;
											$.ajax({
										      	url: url,
										      	type: 'POST',
										      	dataType: 'html',
										      	data: {cid : arrCid, khachhang : arrKhachhang},
										      	success: function(html){
										           $('#ajax-khachhang').html(html);
										       	},
										       	complete : function(){ $('.loading_page').remove();}
										   	});
										} else {
											$('#ajax-khachhang').text('');
										}
									}

									$(document).ready(function(){
										kiemtraCheck();
										loadKhachhang();
										$('.tblFilter input[type=checkbox]').click(function(){
											loadKhachhang();
										});
									});
								</script>
							</fieldset>
							<div class="btlFiller">
								
							</div>
							<div id="ajax-khachhang"></div>
						</div>
					</div>
				</div>
				<div id="tabs-3">
					<div class="tblForm">
						<div class="tbl_content">
							<table class="tbl">
								<tr>
									<td class="label">Tiêu đề <span class="red">*</span></td>
									<td><?php echo $title;?></td>
								</tr>
								<tr>
									<td class="label">Nội dung <span class="red">*</span></td>
									<td><?php echo $noidungemail;?></td>
								</tr>
								<tr>
									<td class="label">File đính kèm</td>
									<td><?php echo $file;?></td>
								</tr>
							</table>
						</div>
					</div>
				</div>
			</div>
		</form>
	</div>
	
	<script type="text/javascript">
		
	</script>
</div>
<div class="clr"></div>	